<!DOCTYPE html>
<html>
<head>
    <title>商学院讲师信息表</title>
	<#include "/header.html">
</head>
<body>
<style>
    th{
        text-align: center;
    }
</style>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <div class="grid-btn">
            <a class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
            <a class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
        <table id="jqGrid"></table>
        <div id="jqGridPager"></div>
    </div>

    <div v-show="!showList" class="panel panel-default">
        <div class="panel-heading">{{title}}</div>
        <form class="form-horizontal">
                    <div class="form-group">
                        <div class="col-sm-2 control-label">讲师userid(可能为空)</div>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" v-model="bBusinessLecturer.userId" placeholder="讲师userid(可能为空)" maxlength="10"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">讲师姓名</div>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" v-model="bBusinessLecturer.authorName" placeholder="讲师姓名" maxlength="20"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">讲师封面</div>
                        <div class="col-sm-10">
                            <input type="file" accept="image/png,image/jpg,image/jpeg" class="form-control" value="选择封面"
                                   placeholder="讲师封面" onchange="insertImg(this)"/>
                            <img :src="bBusinessLecturer.authorCover" alt="讲师封面" id="imgUrl" style="width: 150px; height: 150px">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">讲师简介</div>
                        <div class="col-sm-10">
                            <textarea class="form-control" v-model="bBusinessLecturer.authorIntroduce" placeholder="讲师简介"
                                      rows="8" maxlength="50"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">讲师状态</div>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="deleteState" value="0" v-model="bBusinessLecturer.status"/> 删除
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="deleteState" value="1" v-model="bBusinessLecturer.status"/> 正常
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">创建时间</div>
                        <div class="col-sm-10">
                            <input disabled type="text" class="form-control" v-model="bBusinessLecturer.createTime" placeholder="创建时间"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">修改时间</div>
                        <div class="col-sm-10">
                            <input disabled type="text" class="form-control" v-model="bBusinessLecturer.updateTime" placeholder="修改时间"/>
                        </div>
                    </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
            </div>
        </form>
    </div>
</div>

<script src="${request.contextPath}/statics/js/modules/sys/bbusinesslecturer.js?_${.now?long}"></script>
<script src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.0.0.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
    function insertImg(e) {
        var files = e.files;
        var length = files.length;
        upload(files[0]);
    }

    function upload(file, pathname = "lecturerImgUrl") {
        console.log(file);
        var client = new window.OSS({
            region: 'oss-cn-shenzhen', // 你的oss地址，hangzhou，shanghai，shenzhen
            accessKeyId: 'LTAI4Fh7PnYLw3uQvoUYiazS', //你的ak
            accessKeySecret: 'cEw7e8QMz0h4XY4qmzCoTzhHITqyUU', //你的secret
            //stsToken: '<Your securityToken(STS)>',//这里我暂时没用，注释掉
            bucket: 'zktuistatic', //你的oss名字
        });

        // 组装文件名
        var date = new Date();
        var yeaer = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var datePath = yeaer + "" + month + "" + day;
        var key = "";
        key = pathname + "/" + datePath + "/image" + String(parseInt(Math.random() * 10000000, 10) + getFileExtendingName(
            file.name));

        client.put(key, file).then(function () {
            return client.get(key);
        }).then(function (ret) {
            console.log(ret.res.requestUrls[0]);
            vm.bBusinessLecturer.authorCover = ret.res.requestUrls[0].replace("http://zktuistatic.oss-cn-shenzhen.aliyuncs.com/",
                "http://zktfile.wxslzf.com/");
            document.getElementById('imgUrl').src = vm.bBusinessLecturer.authorCover;
        }).catch(function (err) {
            console.log(err);
        });
    }

    function getFileExtendingName(filename) {
        // 文件扩展名匹配正则
        var reg = /\.[^\.]+$/;
        var matches = reg.exec(filename);
        if (matches) {
            return matches[0];
        }
        return '';
    }
</script>
</body>
</html>
